package umacis.lwuitcomponent.property;

import java.util.Enumeration;
import java.util.Vector;

public class Properties {
	
	private class PropertyFlags {
		private static final int MAXLONGS = 2;
		private static final int NUMBEROFBITSINLONG = 64;
		long flags[] = new long[MAXLONGS];
		public void setModified(int propertyIndex) {
			flags[propertyIndex/NUMBEROFBITSINLONG] |= (1 << (propertyIndex%NUMBEROFBITSINLONG));
		}
		public void setUmmodified(int propertyIndex) {
			flags[propertyIndex/NUMBEROFBITSINLONG] ^= (1 << (propertyIndex%NUMBEROFBITSINLONG));
		}
		public boolean isModified(int propertyIndex) {
			return (flags[propertyIndex/NUMBEROFBITSINLONG] & 
						(1 << (propertyIndex%NUMBEROFBITSINLONG))  )  != 0;
		}
	}
	Vector properties = new Vector();
	private PropertyFlags propertyFlags = new PropertyFlags();
	
	public Properties defaultingTo(Properties propertiesToImpose) {
		if (propertiesToImpose != null) {
			
		}
		//XXX
		return new Properties();
	}
	
	public int getInt(int defaultchildtoshow) {
		return defaultchildtoshow;
	}

	public boolean getBoolean(int dialogIsdialog) {
		return false;
	}

	public Enumeration elements() {
		return properties.elements();
	}

	public void removeProperty(int property) {
		int index = properties.indexOf(new Property(property, 0));
		if (index < 0) return;

		properties.removeElementAt(index);
		propertyFlags.setModified(property);
	}
	
	public void set(int property, int parameter) {
		Property propertyToAdd = new Property(property, parameter);
		int index = properties.indexOf(propertyToAdd);
		if (index < 0) {
			properties.addElement(propertyToAdd);
			propertyFlags.setModified(property);
			return;
		}
		((Property)properties.elementAt(index)).parameter = parameter;
		
	}

	public void set(int property, boolean boolean1) {
		Property propertyToAdd = new Property(property, boolean1);
		int index = properties.indexOf(propertyToAdd);
		if (index < 0) {
			properties.addElement(propertyToAdd);
			propertyFlags.setModified(property);
			return;
		}
		((Property)properties.elementAt(index)).boolean1 = boolean1;
	}

	public void set(int property, String string) {
		Property propertyToAdd = new Property(property, string);
		int index = properties.indexOf(propertyToAdd);
		if (index < 0) {
			properties.addElement(propertyToAdd);
			propertyFlags.setModified(property);
			return;
		}
		((Property)properties.elementAt(index)).string = string;
	}
	
	
		
		
	
}
